//app.js
App({
  onLaunch: function () {

    // wx.getLocation({
    //   type: 'wgs84',
    //   success:  res => {
    //     this.globalData.location.lat = res.latitude
    //     this.globalData.location.lon = res.longitude
    //     // var speed = res.speed
    //     // var accuracy = res.accuracy
    //   }
    // }),

  wx.getSystemInfo({
      success: res => {
        this.globalData.winHei = res.windowHeight;
        this.globalData.winWid = res.windowWidth;
        this.globalData.brand = res.brand;
        this.globalData.model = res.model;
        // console.log('手机品牌：' + res.brand)
        // console.log('手机型号：' + res.model)
        // console.log(res.pixelRatio)
        // console.log(res.windowWidth)
        // console.log(res.windowHeight)
        // console.log(res.language)
        // console.log('微信版本号:' + res.version)
        // console.log('客户端平台' + res.platform)
      }
    });

    // 获取用户信息
    // wx.getSetting({
    //   success: res => {
    //     debugger;
    //     console.log(res);
    //     if (res.authSetting['scope.userInfo']) {
    //       // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
    //       wx.getUserInfo({
    //         success: res => {
    //           // 可以将 code 发送给后台解码出 unionId
    //           this.globalData.userInfo = res.userInfo
    //           // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
    //           // 所以此处加入 callback 以防止这种情况
    //           if (this.userInfoReadyCallback) {
    //             this.userInfoReadyCallback(res)
    //           }
    //         }
    //       })
    //     }
    //   }
    // })
  },  
  
  //获取用户信息
  getUserInfo: function (cb) {
    var that = this;
    //调用登录接口
    wx.login({
      success: function (r) {
        that.globalData.userCode = r.code;
        wx.getUserInfo({
          success: function (res) {
            that.globalData.userInfo = res.userInfo;
            typeof cb == "function" && cb(that.globalData.userInfo);
          },
          fail: function (res) {
            typeof cb == "function" && cb(that.globalData.userInfo);
          }
        })
      }
    })

  },

  //获取总店信息
  getStoreInfo: function(){
    //return wx.getStorageSync('storeInfo') || {}
    return this.globalData.storeInfo
  },
  //设置总店信息
  setStoreInfo: function (info) {
    //wx.setStorageSync('storeInfo', info);
    this.globalData.storeInfo = info;
  },

  // 会员uid
  setUid: function (uid) {
    this.globalData.uid = uid;
  },
  getUid: function () {
    return this.globalData.uid;
  },

  //会员个人信息
  getUInfo: function(){
    return this.globalData.userInfo;
  },
  setUInfo: function (userInfo) {
    this.globalData.userInfo = userInfo;
  },

  // setUserSid: function (sid) {
  //   this.globalData.userSid = sid;
  // },
  // getUserSid: function () {
  //   return this.globalData.userSid;
  // },
  setOpenId(openId) {
    this.globalData.openId = openId;
  },
  getOpenId() {
    return this.globalData.openId;
  },
  getHost() {
    return this.config.apiUrl;
  },
  setHost(host) {
    this.config.apiUrl = host;
  },
  getAlias() {
    return this.globalData.alias;
  },
  setAlias(alias) {
    this.globalData.alias = alias;
  },
  setLocation(lat, lng) {
    this.globalData.location = {
      lng,
      lat
    };
  },
  getLocation() {
    return this.globalData.location;
  },
  getUserId() {
    return this.globalData.user_id;
  },
  setUserId(user_id) {
    this.globalData.user_id = user_id;
  },
  getWinHei() {
    return this.globalData.winHei;
  },
  setWinHei(winHei) {
    this.globalData.winHei = winHei;
  },
  getWinWid() {
    return this.globalData.winWid;
  },
  setWinWid(winWid) {
    this.globalData.winWid = winWid;
  },

  //员工所属店铺id
  getEmployeeSid() {
    return wx.getStorageSync('eSid') || ''
  },
  setEmployeeSid(eSid) {
    wx.setStorageSync('eSid', eSid);
    //this.globalData.eSid = eSid;
  },

  // 员工id
  getEmployeeid(){
     return wx.getStorageSync('eid') || ''
    //return this.globalData.eid;
  },
  setEmployeeid(eid) {
    wx.setStorageSync('eid', eid);
    //this.globalData.eid = eid;
  },


  getLogoImg() {
    return this.globalData.logoImg;
  },
  setLogoImg(logoImg) {
    this.globalData.logoImg = logoImg;
  },
  getShareTitle() {
    return this.globalData.shareTit;
  },
  setShareTitle(shareTitle) {
    this.globalData.shareTitle = shareTitle;
  },
  getMarketTitle() {
    return this.globalData.marketTitle;
  },
  setMarketTitle(marketTitle) {
    this.globalData.marketTitle = marketTitle;
  },
  getBrand(brand){
    return this.globalData.brand;
  },
  getModel(model){
    return this.globalData.model;
  },

  // 推荐人id
  getRecuid() {
    return wx.getStorageSync('recuid') || ''
  },
  setRecuid(recuid) {
    wx.setStorageSync('recuid', recuid);
  },

  getMobile() {
    return this.globalData.userInfo.mobile;
  },
  setMobile(mobile) {
    this.globalData.userInfo.mobile = mobile;
  },
  getFloorId(){
    return this.globalData.getFloorId;
  },
  setFloorId(floorId) {
    this.globalData.getFloorId = floorId;
  },

  globalData: {

    brand: null,
    model: null,
    mobile: "",

    storeInfo: {},
    //openId: null,
    uid: null,
    //userSid: '',
    userInfo: null,
    location: {
      lng: '',
      lat: '',
    },
    isPay: false,
    user_id: null,
    winHei: 0,
    winWid: 0,
    eSid: null,
    eid: null,
    logoImg: null,
    marketTitle: null,
    shareTitle: null,
    recuid:"",
    floorId:null

  },
  config: {
    //apiUrl: 'https://weixin.sundayer.cn/api/index.php?'
    apiUrl: 'https://apizjwd.88ff.com/index.php?'
  }
})
